{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [],
   "source": [
    "#先写一下通用的东西\n",
    "import requests #导入requests模块\n",
    "import json\n",
    "create_facelists_url = \"https://api-ttg.cognitiveservices.azure.com/face/v1.0/facelists/{faceListId}\" \n",
    "subscription_key = \"24655b0092b8488798cf821ce6b91284\"\n",
    "assert subscription_key\n",
    "headers = {\n",
    "    # Request headers\n",
    "    'Content-Type': 'application/json',\n",
    "    'Ocp-Apim-Subscription-Key': subscription_key,\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 封装成函数方便添加图片\n",
    "def AddFace(img_url=str,userData=str):\n",
    "    add_face_url =\"https://api-ttg.cognitiveservices.azure.com/face/v1.0/facelists/{faceListId}\"\n",
    "    subscription_key = \"24655b0092b8488798cf821ce6b91284\"\n",
    "    assert subscription_key\n",
    "    headers = {\n",
    "        # Request headers\n",
    "        'Content-Type': 'application/json',\n",
    "        'Ocp-Apim-Subscription-Key': subscription_key,\n",
    "    }\n",
    "    img_url = img_url\n",
    "\n",
    "    params_add_face={\n",
    "        \"faceListId\":\"who3\",\n",
    "        \"userData\":userData\n",
    "    }\n",
    "    r_add_face = requests.post(add_face_url,headers=headers,params=params_add_face,json={\"url\":img_url})\n",
    "    return r_add_face.status_code#返回出状态码"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "409"
      ]
     },
     "execution_count": 96,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 1、create 创建一个装相片的列表\n",
    "data = {\n",
    "    \"name\": \"list_pm_c\",\n",
    "    \"userData\": \"我的同学们\",\n",
    "    \"recognitionModel\": \"recognition_02\"\n",
    "}\n",
    "params = {\n",
    "    # Request parameters    \n",
    "   \n",
    "    \"faceListId\":\"who3\"\n",
    "    \n",
    "#     'detectionModel': 'detection_01',\n",
    "}\n",
    "r_create = requests.put(create_facelists_url,headers=headers,params=params,json=data)\n",
    "# 请求成功，返回空字符串\n",
    "r_create.status_code"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "b''"
      ]
     },
     "execution_count": 84,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_create.content"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "metadata": {},
   "outputs": [],
   "source": [
    "#先加一张脸试试\n",
    "# 2、Add face\n",
    "add_face_url =\"https://api-ttg.cognitiveservices.azure.com/face/v1.0/facelists/{faceListId}/persistedFaces\"\n",
    "subscription_key = \"24655b0092b8488798cf821ce6b91284\"\n",
    "assert subscription_key\n",
    "headers = {\n",
    "    # Request headers\n",
    "    'Content-Type': 'application/json',\n",
    "    'Ocp-Apim-Subscription-Key': subscription_key,\n",
    "}\n",
    "img_url = \"https://china.nba.com/media/img/players/head/260x190/203500.png\"\n",
    "\n",
    "params_add_face={\n",
    "    \"faceListId\":\"who3\",\n",
    "    \"userData\":\"亚当斯\"\n",
    "}\n",
    "\n",
    "r_add_face = requests.post(add_face_url,headers=headers,params=params_add_face,json={\"url\":img_url})\n",
    "# r = requests.post(add_face, headers=headers,params = params,json={\"url\": add_face_image})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 封装成函数方便添加图片\n",
    "def AddFace(img_url=str,userData=str):\n",
    "    add_face_url =\"https://api-ttg.cognitiveservices.azure.com/face/v1.0/facelists/{faceListId}/persistedFaces\"\n",
    "    subscription_key = \"24655b0092b8488798cf821ce6b91284\"\n",
    "    assert subscription_key\n",
    "    headers = {\n",
    "        # Request headers\n",
    "        'Content-Type': 'application/json',\n",
    "        'Ocp-Apim-Subscription-Key': subscription_key,\n",
    "    }\n",
    "    img_url = img_url\n",
    "\n",
    "    params_add_face={\n",
    "        \"faceListId\":\"who3\",\n",
    "        \"userData\":userData\n",
    "    }\n",
    "    r_add_face = requests.post(add_face_url,headers=headers,params=params_add_face,json={\"url\":img_url})\n",
    "    return r_add_face.status_code#返回出状态码"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "metadata": {},
   "outputs": [],
   "source": [
    " # 顺便把查看列表的也给封装了\n",
    "# Get facelist\n",
    "def GetFacelist():\n",
    "    get_facelist_url = \"https://westcentralus.api.cognitive.microsoft.com/face/v1.0/facelists/{faceListId}\"\n",
    "    data = {\n",
    "        \"faceListId\":\"who3\",\n",
    "    }\n",
    "    r_get_facelist = requests.get(get_facelist_url,headers=headers,params=data)\n",
    "    return r_get_facelist.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "200"
      ]
     },
     "execution_count": 100,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "AddFace(\"https://china.nba.com/media/img/players/head/260x190/2546.png\",\"安东尼\")#可以先用一个试试水"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "200"
      ]
     },
     "execution_count": 104,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "AddFace(\"https://china.nba.com/media/img/players/head/260x190/203507.png\",\"字母哥\")#可以先用一个试试水\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "200"
      ]
     },
     "execution_count": 106,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "AddFace(\"https://china.nba.com/media/img/players/head/260x190/203078.png\",\"比尔\")#可以先用一个试试水\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "200"
      ]
     },
     "execution_count": 108,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "AddFace(\"https://china.nba.com/media/img/players/head/260x190/203552.png\",\"塞斯.库里\")#可以先用一个试试水\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "200"
      ]
     },
     "execution_count": 109,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "AddFace(\"https://china.nba.com/media/img/players/head/260x190/1713.png\",\"卡特\")#可以先用一个试试水\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "200"
      ]
     },
     "execution_count": 110,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "AddFace(\"https://china.nba.com/media/img/players/head/260x190/203954.png\",\"恩比德\")#可以先用一个试试水\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "200"
      ]
     },
     "execution_count": 111,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "AddFace(\"https://china.nba.com/media/img/players/head/260x190/202331.png\",\"保罗乔治\")#可以先用一个试试水\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 112,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "200"
      ]
     },
     "execution_count": 112,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "AddFace(\"https://china.nba.com/media/img/players/head/260x190/201935.png\",\"詹姆斯.哈登\")#可以先用一个试试水\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "200"
      ]
     },
     "execution_count": 113,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "AddFace(\"https://china.nba.com/media/img/players/head/260x190/2544.png\",\"勒布朗.詹姆斯\")#可以先用一个试试水\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 114,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "200"
      ]
     },
     "execution_count": 114,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "AddFace(\"https://china.nba.com/media/img/players/head/260x190/1628398.png\",\"库兹马\")#可以先用一"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 115,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'[{\"faceId\": \"439d1180-8320-4f06-b011-1ac141beb40e\", \"faceRectangle\": {\"top\": 45, \"left\": 98, \"width\": 65, \"height\": 65}, \"faceAttributes\": {\"smile\": 1.0, \"headPose\": {\"pitch\": 7.7, \"roll\": 1.3, \"yaw\": -0.9}, \"gender\": \"male\", \"age\": 29.0, \"facialHair\": {\"moustache\": 0.6, \"beard\": 0.4, \"sideburns\": 0.4}, \"glasses\": \"NoGlasses\", \"emotion\": {\"anger\": 0.0, \"contempt\": 0.0, \"disgust\": 0.0, \"fear\": 0.0, \"happiness\": 1.0, \"neutral\": 0.0, \"sadness\": 0.0, \"surprise\": 0.0}, \"blur\": {\"blurLevel\": \"low\", \"value\": 0.18}, \"exposure\": {\"exposureLevel\": \"goodExposure\", \"value\": 0.67}, \"noise\": {\"noiseLevel\": \"high\", \"value\": 0.85}, \"makeup\": {\"eyeMakeup\": false, \"lipMakeup\": false}, \"accessories\": [], \"occlusion\": {\"foreheadOccluded\": false, \"eyeOccluded\": false, \"mouthOccluded\": false}, \"hair\": {\"bald\": 0.77, \"invisible\": false, \"hairColor\": [{\"color\": \"black\", \"confidence\": 0.99}, {\"color\": \"brown\", \"confidence\": 0.92}, {\"color\": \"gray\", \"confidence\": 0.54}, {\"color\": \"blond\", \"confidence\": 0.28}, {\"color\": \"other\", \"confidence\": 0.14}, {\"color\": \"red\", \"confidence\": 0.01}]}}}]'"
      ]
     },
     "execution_count": 115,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 3、检测人脸的id\n",
    "# replace <My Endpoint String> with the string from your endpoint URL\n",
    "face_api_url = 'https://api-ttg.cognitiveservices.azure.com/face/v1.0/detect'\n",
    "\n",
    "# 请求正文\n",
    "image_url = 'https://china.nba.com/media/img/players/head/260x190/201939.png'\n",
    "\n",
    "headers = {'Ocp-Apim-Subscription-Key': subscription_key}\n",
    "\n",
    "# 请求参数\n",
    "params = {\n",
    "    'returnFaceId': 'true',\n",
    "    'returnFaceLandmarks': 'false',\n",
    "    # 选择model\n",
    "    'recognitionModel':'recognition_02',\n",
    "    'detectionModel':'detection_01',\n",
    "    # 可选参数,请仔细阅读API文档\n",
    "    'returnFaceAttributes': 'age,gender,headPose,smile,facialHair,glasses,emotion,hair,makeup,occlusion,accessories,blur,exposure,noise',\n",
    "}\n",
    "\n",
    "response = requests.post(face_api_url, params=params,\n",
    "                         headers=headers, json={\"url\": image_url})\n",
    "# json.dumps 将json--->字符串\n",
    "json.dumps(response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "metadata": {},
   "outputs": [],
   "source": [
    "我的脸 = response.json()[0][\"faceId\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 117,
   "metadata": {},
   "outputs": [],
   "source": [
    "#4、Find similars\n",
    "\n",
    "findsimilars_url = \"https://api-ttg.cognitiveservices.azure.com/face/v1.0/findsimilars\"\n",
    "\n",
    "# 请求正文 faceId需要先检测一张照片获取\n",
    "data_findsimilars = {\n",
    "    \"faceId\":我的脸,\n",
    "    \"faceListId\":\"who3\",\n",
    "    \"maxNumOfCandidatesReturned\": 10,\n",
    "    \"mode\": \"matchFace\"#matchPerson\n",
    "    }\n",
    "\n",
    "r_findsimilars = requests.post(findsimilars_url,headers=headers,json=data_findsimilars)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 118,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "200"
      ]
     },
     "execution_count": 118,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_findsimilars.status_code"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 119,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'persistedFaceId': 'b78d812f-2c98-4bd2-9310-ded35974ed52',\n",
       "  'confidence': 0.32838},\n",
       " {'persistedFaceId': 'cc04a8f9-7427-4dc8-851b-7a563d16f77e',\n",
       "  'confidence': 0.32838},\n",
       " {'persistedFaceId': '647f6568-b37e-42b9-b1f2-a8b829a6ffa4',\n",
       "  'confidence': 0.18088},\n",
       " {'persistedFaceId': 'b854810d-8697-4f06-9b01-1bf8055cd86b',\n",
       "  'confidence': 0.14569},\n",
       " {'persistedFaceId': '68fe44ec-aafe-4833-b06a-776230ee86a5',\n",
       "  'confidence': 0.09854},\n",
       " {'persistedFaceId': '7049fbe4-0bb4-4d99-aa48-4083a1f84103',\n",
       "  'confidence': 0.09845},\n",
       " {'persistedFaceId': '0c064195-5db2-4fa7-b6d3-c9375c0ed163',\n",
       "  'confidence': 0.0924},\n",
       " {'persistedFaceId': 'd6acb481-ffd8-483f-9285-0ed08eb48b61',\n",
       "  'confidence': 0.08719},\n",
       " {'persistedFaceId': '7fa427a6-5bd3-4085-baee-608487802570',\n",
       "  'confidence': 0.08719},\n",
       " {'persistedFaceId': 'e5329c91-115e-4c1a-a903-93915186f446',\n",
       "  'confidence': 0.08719}]"
      ]
     },
     "execution_count": 119,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_findsimilars.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 120,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'persistedFaces': [{'persistedFaceId': '28613b16-7753-4d18-b637-d9f8c5bba4a8',\n",
       "   'userData': '亚当斯'},\n",
       "  {'persistedFaceId': 'e843d4c4-8407-4408-8968-75913e1ad877',\n",
       "   'userData': '亚当斯'},\n",
       "  {'persistedFaceId': '0c064195-5db2-4fa7-b6d3-c9375c0ed163',\n",
       "   'userData': '安东尼'},\n",
       "  {'persistedFaceId': 'd6acb481-ffd8-483f-9285-0ed08eb48b61',\n",
       "   'userData': '字母哥'},\n",
       "  {'persistedFaceId': '7fa427a6-5bd3-4085-baee-608487802570',\n",
       "   'userData': '字母哥'},\n",
       "  {'persistedFaceId': '647f6568-b37e-42b9-b1f2-a8b829a6ffa4',\n",
       "   'userData': '鲍尔'},\n",
       "  {'persistedFaceId': '7bb083c8-04ab-40a5-87c5-eb5115ff7c63',\n",
       "   'userData': '比尔'},\n",
       "  {'persistedFaceId': 'b78d812f-2c98-4bd2-9310-ded35974ed52',\n",
       "   'userData': '塞斯.库里'},\n",
       "  {'persistedFaceId': '14ebbdd7-a87d-4bc9-8aef-bcd7d790aade',\n",
       "   'userData': '卡特'},\n",
       "  {'persistedFaceId': '6f8a3eae-5686-453f-93f0-1b98ca0d6299',\n",
       "   'userData': '恩比德'},\n",
       "  {'persistedFaceId': 'e5329c91-115e-4c1a-a903-93915186f446',\n",
       "   'userData': '字母哥'},\n",
       "  {'persistedFaceId': '919221d0-1c8e-4d11-8567-5ff2b9ff00e6',\n",
       "   'userData': '比尔'},\n",
       "  {'persistedFaceId': '2708f143-ed4d-43d9-8217-584cee533dd7',\n",
       "   'userData': '比尔'},\n",
       "  {'persistedFaceId': 'cc04a8f9-7427-4dc8-851b-7a563d16f77e',\n",
       "   'userData': '塞斯.库里'},\n",
       "  {'persistedFaceId': '47725ee4-e6f2-463d-857f-4a8e2ca163d1',\n",
       "   'userData': '卡特'},\n",
       "  {'persistedFaceId': 'f44ae547-d95f-4618-94f4-c702a3e57886',\n",
       "   'userData': '恩比德'},\n",
       "  {'persistedFaceId': '7049fbe4-0bb4-4d99-aa48-4083a1f84103',\n",
       "   'userData': '保罗乔治'},\n",
       "  {'persistedFaceId': '7d101384-d2cd-4c6c-9cd6-dddf29ed5c6e',\n",
       "   'userData': '詹姆斯.哈登'},\n",
       "  {'persistedFaceId': '68fe44ec-aafe-4833-b06a-776230ee86a5',\n",
       "   'userData': '勒布朗.詹姆斯'},\n",
       "  {'persistedFaceId': 'b854810d-8697-4f06-9b01-1bf8055cd86b',\n",
       "   'userData': '库兹马'}],\n",
       " 'faceListId': 'who3',\n",
       " 'name': 'list_pm_c',\n",
       " 'userData': '我的同学们'}"
      ]
     },
     "execution_count": 120,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd #别忘了导入我们的伙伴pandas哦\n",
    "get_facelist_url = \"https://api-ttg.cognitiveservices.azure.com/face/v1.0/facelists/{faceListId}\"\n",
    "\n",
    "data = {\n",
    "    \"faceListId\":\"who3\",\n",
    "\n",
    "}\n",
    "\n",
    "r_get_facelist = requests.get(get_facelist_url,headers=headers,params=data)\n",
    "r_get_facelist.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 121,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>persistedFaceId</th>\n",
       "      <th>userData</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>28613b16-7753-4d18-b637-d9f8c5bba4a8</td>\n",
       "      <td>亚当斯</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>e843d4c4-8407-4408-8968-75913e1ad877</td>\n",
       "      <td>亚当斯</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0c064195-5db2-4fa7-b6d3-c9375c0ed163</td>\n",
       "      <td>安东尼</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>d6acb481-ffd8-483f-9285-0ed08eb48b61</td>\n",
       "      <td>字母哥</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7fa427a6-5bd3-4085-baee-608487802570</td>\n",
       "      <td>字母哥</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>647f6568-b37e-42b9-b1f2-a8b829a6ffa4</td>\n",
       "      <td>鲍尔</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>7bb083c8-04ab-40a5-87c5-eb5115ff7c63</td>\n",
       "      <td>比尔</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>b78d812f-2c98-4bd2-9310-ded35974ed52</td>\n",
       "      <td>塞斯.库里</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>14ebbdd7-a87d-4bc9-8aef-bcd7d790aade</td>\n",
       "      <td>卡特</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>6f8a3eae-5686-453f-93f0-1b98ca0d6299</td>\n",
       "      <td>恩比德</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>e5329c91-115e-4c1a-a903-93915186f446</td>\n",
       "      <td>字母哥</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>919221d0-1c8e-4d11-8567-5ff2b9ff00e6</td>\n",
       "      <td>比尔</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>2708f143-ed4d-43d9-8217-584cee533dd7</td>\n",
       "      <td>比尔</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>cc04a8f9-7427-4dc8-851b-7a563d16f77e</td>\n",
       "      <td>塞斯.库里</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>47725ee4-e6f2-463d-857f-4a8e2ca163d1</td>\n",
       "      <td>卡特</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>f44ae547-d95f-4618-94f4-c702a3e57886</td>\n",
       "      <td>恩比德</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>7049fbe4-0bb4-4d99-aa48-4083a1f84103</td>\n",
       "      <td>保罗乔治</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>7d101384-d2cd-4c6c-9cd6-dddf29ed5c6e</td>\n",
       "      <td>詹姆斯.哈登</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>68fe44ec-aafe-4833-b06a-776230ee86a5</td>\n",
       "      <td>勒布朗.詹姆斯</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>b854810d-8697-4f06-9b01-1bf8055cd86b</td>\n",
       "      <td>库兹马</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                         persistedFaceId userData\n",
       "0   28613b16-7753-4d18-b637-d9f8c5bba4a8      亚当斯\n",
       "1   e843d4c4-8407-4408-8968-75913e1ad877      亚当斯\n",
       "2   0c064195-5db2-4fa7-b6d3-c9375c0ed163      安东尼\n",
       "3   d6acb481-ffd8-483f-9285-0ed08eb48b61      字母哥\n",
       "4   7fa427a6-5bd3-4085-baee-608487802570      字母哥\n",
       "5   647f6568-b37e-42b9-b1f2-a8b829a6ffa4       鲍尔\n",
       "6   7bb083c8-04ab-40a5-87c5-eb5115ff7c63       比尔\n",
       "7   b78d812f-2c98-4bd2-9310-ded35974ed52    塞斯.库里\n",
       "8   14ebbdd7-a87d-4bc9-8aef-bcd7d790aade       卡特\n",
       "9   6f8a3eae-5686-453f-93f0-1b98ca0d6299      恩比德\n",
       "10  e5329c91-115e-4c1a-a903-93915186f446      字母哥\n",
       "11  919221d0-1c8e-4d11-8567-5ff2b9ff00e6       比尔\n",
       "12  2708f143-ed4d-43d9-8217-584cee533dd7       比尔\n",
       "13  cc04a8f9-7427-4dc8-851b-7a563d16f77e    塞斯.库里\n",
       "14  47725ee4-e6f2-463d-857f-4a8e2ca163d1       卡特\n",
       "15  f44ae547-d95f-4618-94f4-c702a3e57886      恩比德\n",
       "16  7049fbe4-0bb4-4d99-aa48-4083a1f84103     保罗乔治\n",
       "17  7d101384-d2cd-4c6c-9cd6-dddf29ed5c6e   詹姆斯.哈登\n",
       "18  68fe44ec-aafe-4833-b06a-776230ee86a5  勒布朗.詹姆斯\n",
       "19  b854810d-8697-4f06-9b01-1bf8055cd86b      库兹马"
      ]
     },
     "execution_count": 121,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "adf = pd.json_normalize(r_get_facelist.json()[\"persistedFaces\"])# 升级pandas才能运行\n",
    "adf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 122,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>persistedFaceId</th>\n",
       "      <th>confidence</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>b78d812f-2c98-4bd2-9310-ded35974ed52</td>\n",
       "      <td>0.32838</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>cc04a8f9-7427-4dc8-851b-7a563d16f77e</td>\n",
       "      <td>0.32838</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>647f6568-b37e-42b9-b1f2-a8b829a6ffa4</td>\n",
       "      <td>0.18088</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>b854810d-8697-4f06-9b01-1bf8055cd86b</td>\n",
       "      <td>0.14569</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>68fe44ec-aafe-4833-b06a-776230ee86a5</td>\n",
       "      <td>0.09854</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>7049fbe4-0bb4-4d99-aa48-4083a1f84103</td>\n",
       "      <td>0.09845</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>0c064195-5db2-4fa7-b6d3-c9375c0ed163</td>\n",
       "      <td>0.09240</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>d6acb481-ffd8-483f-9285-0ed08eb48b61</td>\n",
       "      <td>0.08719</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>7fa427a6-5bd3-4085-baee-608487802570</td>\n",
       "      <td>0.08719</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>e5329c91-115e-4c1a-a903-93915186f446</td>\n",
       "      <td>0.08719</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                        persistedFaceId  confidence\n",
       "0  b78d812f-2c98-4bd2-9310-ded35974ed52     0.32838\n",
       "1  cc04a8f9-7427-4dc8-851b-7a563d16f77e     0.32838\n",
       "2  647f6568-b37e-42b9-b1f2-a8b829a6ffa4     0.18088\n",
       "3  b854810d-8697-4f06-9b01-1bf8055cd86b     0.14569\n",
       "4  68fe44ec-aafe-4833-b06a-776230ee86a5     0.09854\n",
       "5  7049fbe4-0bb4-4d99-aa48-4083a1f84103     0.09845\n",
       "6  0c064195-5db2-4fa7-b6d3-c9375c0ed163     0.09240\n",
       "7  d6acb481-ffd8-483f-9285-0ed08eb48b61     0.08719\n",
       "8  7fa427a6-5bd3-4085-baee-608487802570     0.08719\n",
       "9  e5329c91-115e-4c1a-a903-93915186f446     0.08719"
      ]
     },
     "execution_count": 122,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bdf = pd.json_normalize(r_findsimilars.json())# 升级pandas才能运行\n",
    "bdf\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>persistedFaceId</th>\n",
       "      <th>userData</th>\n",
       "      <th>confidence</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>b78d812f-2c98-4bd2-9310-ded35974ed52</td>\n",
       "      <td>塞斯.库里</td>\n",
       "      <td>0.32838</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>cc04a8f9-7427-4dc8-851b-7a563d16f77e</td>\n",
       "      <td>塞斯.库里</td>\n",
       "      <td>0.32838</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>647f6568-b37e-42b9-b1f2-a8b829a6ffa4</td>\n",
       "      <td>鲍尔</td>\n",
       "      <td>0.18088</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>b854810d-8697-4f06-9b01-1bf8055cd86b</td>\n",
       "      <td>库兹马</td>\n",
       "      <td>0.14569</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>68fe44ec-aafe-4833-b06a-776230ee86a5</td>\n",
       "      <td>勒布朗.詹姆斯</td>\n",
       "      <td>0.09854</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>7049fbe4-0bb4-4d99-aa48-4083a1f84103</td>\n",
       "      <td>保罗乔治</td>\n",
       "      <td>0.09845</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0c064195-5db2-4fa7-b6d3-c9375c0ed163</td>\n",
       "      <td>安东尼</td>\n",
       "      <td>0.09240</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>d6acb481-ffd8-483f-9285-0ed08eb48b61</td>\n",
       "      <td>字母哥</td>\n",
       "      <td>0.08719</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>7fa427a6-5bd3-4085-baee-608487802570</td>\n",
       "      <td>字母哥</td>\n",
       "      <td>0.08719</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>e5329c91-115e-4c1a-a903-93915186f446</td>\n",
       "      <td>字母哥</td>\n",
       "      <td>0.08719</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                        persistedFaceId userData  confidence\n",
       "4  b78d812f-2c98-4bd2-9310-ded35974ed52    塞斯.库里     0.32838\n",
       "6  cc04a8f9-7427-4dc8-851b-7a563d16f77e    塞斯.库里     0.32838\n",
       "3  647f6568-b37e-42b9-b1f2-a8b829a6ffa4       鲍尔     0.18088\n",
       "9  b854810d-8697-4f06-9b01-1bf8055cd86b      库兹马     0.14569\n",
       "8  68fe44ec-aafe-4833-b06a-776230ee86a5  勒布朗.詹姆斯     0.09854\n",
       "7  7049fbe4-0bb4-4d99-aa48-4083a1f84103     保罗乔治     0.09845\n",
       "0  0c064195-5db2-4fa7-b6d3-c9375c0ed163      安东尼     0.09240\n",
       "1  d6acb481-ffd8-483f-9285-0ed08eb48b61      字母哥     0.08719\n",
       "2  7fa427a6-5bd3-4085-baee-608487802570      字母哥     0.08719\n",
       "5  e5329c91-115e-4c1a-a903-93915186f446      字母哥     0.08719"
      ]
     },
     "execution_count": 123,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.merge(adf, bdf,how='inner', on='persistedFaceId').sort_values(by=\"confidence\",ascending = False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
